package com.ww.util.guava;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.common.base.Joiner;
import com.google.common.collect.Maps;

public class CollectionToStr {

	public static void main(String[] args) {
		/**
		 * 将集合转换为特定规则的字符串
		 */
		List<String> list = new ArrayList<>();
		list.add("aa");
		list.add("bb");
		list.add("cc");
		String str = list.get(0);
		for (int i = 1; i < list.size(); i++) {
			str = str + "-" + list.get(i);
		}
		System.out.println(str);
		
		System.out.println("**********************");
		
		List<String> list2 = new ArrayList<>();
		list2.add("aa");
		list2.add("bb");
		list2.add("cc");
		String result = Joiner.on("-").join(list2);
		System.out.println(result);
		
		System.out.println("**********************");
		
		/**
		 * 把map集合转换为特定规则的字符串
		 */
		Map<String, Integer> map = Maps.newHashMap();
		map.put("xiaoming", 12);
		map.put("xiaohong", 13);
		String result2 = Joiner.on(",").withKeyValueSeparator("=").join(map);
		/**
		 * 打印：xiaohong=13,xiaoming=12
		 */
		System.out.println(result2);
	}
}
